﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmNganhdaotao.
	/// </summary>
	public class frmNganhdaotao : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
        int flag = 0;
		private System.Windows.Forms.DataGrid dgrDanhMuc4;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtMa;
		private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbonhom;
        private TextBox tenvt;
        private Label label4;
        private Label label5;
        private TextBox txt_stt;
        private Button btn_them;
        private Button btn_sua;
        private Button btn_luu;
        private Button btn_boqua;
        private Button btn_xoa;
        private Button btn_thoat;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmNganhdaotao()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmNganhdaotao));
            this.dgrDanhMuc4 = new System.Windows.Forms.DataGrid();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.panel1 = new System.Windows.Forms.Panel();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.btn_xoa = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_them = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.cbonhom = new System.Windows.Forms.ComboBox();
            this.tenvt = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txt_stt = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc4)).BeginInit();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc4
            // 
            this.dgrDanhMuc4.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc4.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc4.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc4.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc4.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc4.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc4.CaptionVisible = false;
            this.dgrDanhMuc4.DataMember = "";
            this.dgrDanhMuc4.FlatMode = true;
            this.dgrDanhMuc4.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc4.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc4.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc4.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc4.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc4.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc4.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc4.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc4.Location = new System.Drawing.Point(8, 8);
            this.dgrDanhMuc4.Name = "dgrDanhMuc4";
            this.dgrDanhMuc4.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc4.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc4.RowHeaderWidth = 10;
            this.dgrDanhMuc4.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc4.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc4.Size = new System.Drawing.Size(508, 312);
            this.dgrDanhMuc4.TabIndex = 15;
            this.dgrDanhMuc4.CurrentCellChanged += new System.EventHandler(this.dgrDanhMuc4_CurrentCellChanged);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(264, 328);
            this.txtTen.MaxLength = 50;
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(252, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(196, 332);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(65, 13);
            this.label2.TabIndex = 121;
            this.label2.Text = "Tên ngành :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(72, 328);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(56, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(43, 332);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(28, 13);
            this.label1.TabIndex = 119;
            this.label1.Text = "Mã :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btn_boqua);
            this.panel1.Controls.Add(this.btn_luu);
            this.panel1.Controls.Add(this.btn_thoat);
            this.panel1.Controls.Add(this.btn_xoa);
            this.panel1.Controls.Add(this.btn_sua);
            this.panel1.Controls.Add(this.btn_them);
            this.panel1.Location = new System.Drawing.Point(80, 388);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(410, 36);
            this.panel1.TabIndex = 5;
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_boqua.Image = global::Human.Properties.Resources.undo_2005;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(201, 3);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(65, 28);
            this.btn_boqua.TabIndex = 3;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(135, 3);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(60, 28);
            this.btn_luu.TabIndex = 2;
            this.btn_luu.Text = "   &Lưu";
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(338, 3);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(60, 28);
            this.btn_thoat.TabIndex = 5;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // btn_xoa
            // 
            this.btn_xoa.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xoa.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xoa.Image = global::Human.Properties.Resources.delete_enabled;
            this.btn_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xoa.Location = new System.Drawing.Point(272, 3);
            this.btn_xoa.Name = "btn_xoa";
            this.btn_xoa.Size = new System.Drawing.Size(60, 28);
            this.btn_xoa.TabIndex = 4;
            this.btn_xoa.Text = "   &Xóa";
            this.btn_xoa.UseVisualStyleBackColor = true;
            this.btn_xoa.Click += new System.EventHandler(this.btn_xoa_Click);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(69, 3);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(60, 28);
            this.btn_sua.TabIndex = 1;
            this.btn_sua.Text = "   &Sửa";
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(3, 3);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(60, 28);
            this.btn_them.TabIndex = 0;
            this.btn_them.Text = "   &Thêm";
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            // 
            // label3
            // 
            this.label3.BackColor = System.Drawing.SystemColors.Control;
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(220, 364);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(41, 13);
            this.label3.TabIndex = 123;
            this.label3.Text = "Nhóm :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cbonhom
            // 
            this.cbonhom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbonhom.Location = new System.Drawing.Point(265, 361);
            this.cbonhom.Name = "cbonhom";
            this.cbonhom.Size = new System.Drawing.Size(133, 21);
            this.cbonhom.TabIndex = 3;
            this.cbonhom.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbonhom_KeyDown);
            // 
            // tenvt
            // 
            this.tenvt.BackColor = System.Drawing.Color.White;
            this.tenvt.Enabled = false;
            this.tenvt.ForeColor = System.Drawing.Color.DarkBlue;
            this.tenvt.Location = new System.Drawing.Point(72, 360);
            this.tenvt.MaxLength = 50;
            this.tenvt.Name = "tenvt";
            this.tenvt.Size = new System.Drawing.Size(135, 20);
            this.tenvt.TabIndex = 2;
            this.tenvt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tenvt_KeyDown);
            // 
            // label4
            // 
            this.label4.BackColor = System.Drawing.SystemColors.Control;
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(6, 364);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(65, 13);
            this.label4.TabIndex = 121;
            this.label4.Text = "Tên ngành :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.BackColor = System.Drawing.SystemColors.Control;
            this.label5.ForeColor = System.Drawing.Color.DarkBlue;
            this.label5.Location = new System.Drawing.Point(404, 364);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(34, 13);
            this.label5.TabIndex = 123;
            this.label5.Text = "STT :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_stt
            // 
            this.txt_stt.Location = new System.Drawing.Point(438, 360);
            this.txt_stt.Name = "txt_stt";
            this.txt_stt.Size = new System.Drawing.Size(78, 20);
            this.txt_stt.TabIndex = 4;
            this.txt_stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_stt_KeyDown);
            // 
            // frmNganhdaotao
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(531, 426);
            this.Controls.Add(this.txt_stt);
            this.Controls.Add(this.cbonhom);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.tenvt);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.dgrDanhMuc4);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmNganhdaotao";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục ngành đào tạo";
            this.Load += new System.EventHandler(this.frmNganhdaotao_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc4)).EndInit();
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmNganhdaotao_Load(object sender, System.EventArgs e)
		{
			load_nhom();
			nghanhdaotao();
			Ena_control(true);
			refresh_Text();
			Ena_textbox(false);
			btn_them.Focus();
		}

		private void load_nhom()
		{
			cbonhom.DisplayMember ="tennhom";
			cbonhom.ValueMember ="manhom";
			cbonhom.DataSource =mDB.get_data("select * from "+ mDB.user+".dmnhomctdt ").Tables[0];
		}

		private void Ena_control(bool ena)
		{
			btn_them.Enabled=ena;
			btn_sua.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_xoa.Enabled=ena;
			btn_thoat.Enabled=ena;
		}
		private void Ena_textbox(bool ena)
		{			
			txtTen.Enabled=ena;
            tenvt.Enabled = ena;
			cbonhom.Enabled =ena;
            txt_stt.Enabled = ena;
		}
		private void clear_Text()
		{			
			txtTen.Clear();
			cbonhom.SelectedIndex =-1;
            txt_stt.Clear();
		}
		private void refresh_Text()
		{
			int i=dgrDanhMuc4.CurrentRowIndex;
			if(i>=0)
			{
				txtMa.Text=dgrDanhMuc4[i,0].ToString();
				txtTen.Text=dgrDanhMuc4[i,1].ToString();
                tenvt.Text = dgrDanhMuc4[i, 2].ToString();
				cbonhom.SelectedValue =dgrDanhMuc4[i,3].ToString();
                txt_stt.Text = dgrDanhMuc4[i, 5].ToString();
			}
		}

		private void nghanhdaotao()
		{
			DataSet ds1=new DataSet();
            ds1 = mDB.get_data("SELECT mactdt,tenctdt,tenvt,ct.manhom,nct.tennhom,stt FROM " + mDB.user + ".ctdaotao ct left join " + mDB.user + ".dmnhomctdt nct on ct.manhom=nct.manhom order by ct.stt");
            dgrDanhMuc4.DataSource=null;
			dgrDanhMuc4.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "mactdt";
			TextCol1.HeaderText = lan.Change_language_MessageText("Mã ngành");
			TextCol1.Width = 80;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc4.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tenctdt";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tên ngành");
			TextCol2.Width = 200;
			TextCol2.ReadOnly=true;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMuc4.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol3 = new DataGridTextBoxColumn();
            TextCol3.MappingName = "tenvt";
            TextCol3.HeaderText = lan.Change_language_MessageText("Tên viết tắt");
            TextCol3.Width = 100;
            TextCol3.ReadOnly = true;
            TextCol3.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol3);
            dgrDanhMuc4.TableStyles.Add(ts);

			DataGridTextBoxColumn TextCol4=new DataGridTextBoxColumn();
			TextCol4.MappingName = "manhom";
			TextCol4.HeaderText = "";
			TextCol4.Width =0;
			TextCol4.ReadOnly=true;
			TextCol4.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol4);
			dgrDanhMuc4.TableStyles.Add(ts);

			DataGridTextBoxColumn TextCol5=new DataGridTextBoxColumn();
			TextCol5.MappingName = "tennhom";
			TextCol5.HeaderText = lan.Change_language_MessageText("Tên nhóm");
			TextCol5.Width = 200;
			TextCol5.ReadOnly=true;
			TextCol5.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol5);
			dgrDanhMuc4.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol6 = new DataGridTextBoxColumn();
            TextCol6.MappingName = "stt";
            TextCol6.HeaderText = lan.Change_language_MessageText("STT");
            TextCol6.Width = 200;
            TextCol6.ReadOnly = true;
            TextCol6.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol6);
            dgrDanhMuc4.TableStyles.Add(ts);
		 			 
			ts.DataGrid.DataSource=ds1.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc4.DataSource, dgrDanhMuc4.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
		}

        private void dgrDanhMuc4_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
				Ena_textbox(false);
				Ena_control(true);
			}
			catch{}
		}

		private void btnKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void txtTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode ==Keys.Enter)
			{				
				SendKeys.Send("{Tab}");
			}
		}

		private void cbonhom_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txtMa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void tenvt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");
        }

        private bool kemtra(string dt)
        {
            bool flag = false;
            try
            {
                flag = mDB.get_data("select count(*) as tong from " + mDB.user + ".llnv where nnghiep='" + dt + "' ").Tables[0].Rows[0][0].ToString().Equals("0");
            }
            catch
            {
                flag = false;
            }
            if (!flag)
                MessageBox.Show(lan.Change_language_MessageText("Ngành đào tạo đã sử dụng không thể hủy!"),AccessData.Msg);
            return flag;
        }

        private void txt_stt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_luu.Focus();
        }
        private string get_maxid()
        {
            int m_tam = 0;
            ds = mDB.get_data("SELECT Max(to_number(mactdt,999)) FROM " + mDB.user + ".ctdaotao");
            if (ds.Tables[0].Rows.Count > 0)
                m_tam = ds.Tables[0].Rows[0][0].ToString() !="" ? int.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1:1;
            else
                m_tam = 1;
            return m_tam.ToString().PadLeft(3, '0').ToString();
        }
        private void btn_them_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            flag = 0;
            txtMa.Text = get_maxid();
            txtTen.Focus();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Ena_control(false);
            Ena_textbox(true);
            txtTen.Focus();
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            int m_id = 0;
            try
            {
                string tvt = "";
                decimal stt = 0;
                string[] mang = txtTen.Text.Split(' ');
                if (!tenvt.Text.Trim().Equals(""))
                    tvt = tenvt.Text.Trim();
                else
                {
                    for (int i = 0; i < mang.Length; i++)
                        tvt += mang[i].Substring(0, 1).ToUpper();
                }
                if (flag == 0)
                {
                    m_id = Int32.Parse(get_maxid());
                    txtMa.Text = m_id.ToString().PadLeft(3, '0');
                }
                else
                {
                    if (txtMa.Text != "")
                        m_id = Int32.Parse(txtMa.Text.ToString());
                }
               
                mDB.upd_DMCTDAOTAO(txtMa.Text, txtTen.Text,tvt, cbonhom.SelectedValue.ToString(), stt);
                nghanhdaotao();
                flag = 0;
                Ena_control(true);
                Ena_textbox(false);
            }
            catch { }
        }

        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            txtTen.Enabled = false;
            cbonhom.Enabled = false;
            txt_stt.Enabled = false;
            refresh_Text();
            btn_thoat.Focus();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ thông tin này?"),AccessData.Msg, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes && kemtra(txtMa.Text.Trim()))
                {
                    mDB.get_data("DELETE  FROM " + mDB.user + ".ctdaotao WHERE mactdt='" + txtMa.Text.Trim() + "'");
                }
                nghanhdaotao();
                refresh_Text();
            }
            catch { }
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

	}
}
